package huaweiod.first;

import java.util.*;

/**
 * 华为OD机试真题 Java 实现【真正的密码】【2022.11 Q4 新题】
 */
public class A_2023_10_RealPassword {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] list = str.split(" ");

        HashSet<String> set = new HashSet<>(Arrays.asList(list));
        ArrayList<String> result = new ArrayList<>();
        for (String s : list) {
            boolean flag = true;
            for (int i = 1; i < s.length(); i++) {
                if(!set.contains(s.substring(0,i))) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                result.add(s);
            }
        }
        result.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if(o1.length() != o2.length()) {
                    return o2.length() - o1.length() ;
                }
                return o2.compareTo(o1);
            }
        });
        if(result.size() > 0) {
            System.out.println(result.get(0));
        }

    }
}
